<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数学数据测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .test-result {
            background: #f0f0f0;
            padding: 10px;
            margin: 10px 0;
            border-radius: 5px;
        }
        .success {
            background: #d4edda;
            color: #155724;
        }
        .error {
            background: #f8d7da;
            color: #721c24;
        }
    </style>
</head>
<body>
    <h1>数学数据测试</h1>
    <div id="results"></div>

    <script type="module">
        import { 
            getAllMathTopics, 
            getMathCategories, 
            getMathTopicsByCategory,
            getRandomPracticeQuestions,
            mistakeBook
        } from './src/data/mathData.js'

        const results = document.getElementById('results')

        function addResult(message, isSuccess = true) {
            const div = document.createElement('div')
            div.className = `test-result ${isSuccess ? 'success' : 'error'}`
            div.textContent = message
            results.appendChild(div)
        }

        try {
            // 测试1: 获取所有数学主题
            const topics = getAllMathTopics()
            addResult(`✅ 成功获取 ${topics.length} 个数学主题`)
            
            // 测试2: 获取所有类别
            const categories = getMathCategories()
            addResult(`✅ 成功获取 ${categories.length} 个类别: ${categories.join(', ')}`)
            
            // 测试3: 测试第一个主题
            if (topics.length > 0) {
                const firstTopic = topics[0]
                addResult(`✅ 第一个主题: ${firstTopic.name} (${firstTopic.category})`)
                addResult(`   难度: ${firstTopic.difficulty}星, 要点: ${firstTopic.keyPoints.length}个`)
            }
            
            // 测试4: 按类别获取主题
            if (categories.length > 0) {
                const categoryTopics = getMathTopicsByCategory(categories[0])
                addResult(`✅ ${categories[0]} 类别有 ${categoryTopics.length} 个主题`)
            }
            
            // 测试5: 获取练习题
            if (topics.length > 0) {
                const questions = getRandomPracticeQuestions(topics[0].id, 3)
                addResult(`✅ 成功生成 ${questions.length} 道练习题`)
            }
            
            // 测试6: 错题本功能
            const mistakes = mistakeBook.getMistakes()
            addResult(`✅ 错题本当前有 ${mistakes.length} 道错题`)
            
            addResult('🎉 所有测试通过！数学学习功能应该可以正常工作了。')
            
        } catch (error) {
            addResult(`❌ 测试失败: ${error.message}`, false)
            console.error('测试错误:', error)
        }
    </script>
</body>
</html> 